﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Remoting.Contexts;
using System.Runtime.Remoting.Messaging;

namespace LeanEngine.Business.Security
{
    internal sealed class SecurityContextProperty : IContextProperty, IContributeServerContextSink
    {
        #region IContextProperty Members

        public void Freeze(Context newContext) { }

        public bool IsNewContextOK(Context newCtx)
        {
            SecurityContextProperty newContextProperty = newCtx.GetProperty(this.Name) as SecurityContextProperty;
            if (newContextProperty == null)
            {
                return false;
            }

            return true;
        }

        public string Name
        {
            get { return "SecurityContextMethodIntercept"; }
        }

        #endregion

        #region IContributeServerContextSink Members

        public IMessageSink GetServerContextSink(IMessageSink nextSink)
        {
            var securitySink = new SecurityMessageSink(nextSink);
            return securitySink;
        }

        #endregion
    }
}
